package com.shaifish.common_sys.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ShaiFish
 */
public class CurrentUserUtil {

    public static Long getCurrentUser() {
        Long user = (Long) getRequestAttr().getRequest().getSession().getAttribute("user");
        return user;
    }

    private static ServletRequestAttributes getRequestAttr() {
        RequestAttributes attr = RequestContextHolder.currentRequestAttributes();
        return (ServletRequestAttributes) attr;
    }

}
